package com.jt.res.config;
import com.jt.res.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 定义Spring Web MVC 配置类
 */
@Configuration
public class SpringWebConfig implements WebMvcConfigurer {


 @Autowired
 private RestTemplate restTemplate;



 /**将拦截器添加到spring mvc的执行链中
     * @param registry 此对象提供了一个list集合,可以将拦截器添加到集合中
     * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

         registry.addInterceptor(new TokenInterceptor(restTemplate))
                 //配置要拦截的url
                 .addPathPatterns("/**");//doCreate,doUpdate,doDelete
    }
}
